import requests
import random
import ddddocr
import time


# 1. 识别验证码 获取cookies
ocr =  ddddocr.DdddOcr(show_ad=False)
img_response = requests.get(f"https://www.labnetwork.com.cn/gateway/basic/mall/oauth/code?{random.random()}")
uuid=img_response.json()["data"]["uuid"]
code = ocr.classification(img_response.json()["data"]["img"][22:])
print(code)

# 2. 模拟登录
response_login = requests.post("https://www.labnetwork.com.cn/gateway/basic/mall/oauth/login", json={
  "userEmail": "2377781078@qq.com",
  "password": "Wert123456",
  "captchaCode": code,
  "captchaKey": uuid
})
print(response_login.json())
token = response_login.json()["data"]["userInfo"]["token"]

# 3. 获取数据
product_response = requests.post("https://www.labnetwork.com.cn/gateway/oldapi/mall/chemical/products", json={
  "query": "",
  "country": "CN",
  "pageSize": 10,
  "chemIds": [],
  "suppliers": [],
  "rank": 0,
  "packSize": "",
  "packUnit": "",
  "unitStock": "",
  "selectedUnit": "",
  "molecularWeightLow": "",
  "molecularWeightHigh": "",
  "locations": [],
  "startRecord": 10,
  "modelRange": [
    84.11,
    1149.73
  ]
}, headers={
  "token": token
})
print(product_response.json())
